<template>
	<div class="layout-pd">
		<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
			<el-table-column prop="hid" label="id" />
			<el-table-column prop="name" label="作业名称"  ></el-table-column>
			<el-table-column  prop="endtime" :formatter="getLocalTime"  label="截止时间"></el-table-column>
		
			<el-table-column label="操作" width="100">
				<template #default="scope">
					<el-button size="small" text type="primary" @click="Jump(scope)">查看</el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
<!-- 		
		<Auth :value="'btn.edit'">
					<div class="flex-warp-item">
						<div class="flex-warp-item-box">
							<el-button type="info" size="default">
								<el-icon>
									<ele-Edit />
								</el-icon>
								编辑
							</el-button>
						</div>
					</div>
				</Auth> -->

</template>

<script setup lang="ts" name="limitsFrontEndBtn">
import { defineAsyncComponent,onMounted,reactive } from 'vue';
import { ElMessage } from 'element-plus';
import { auth, auths, authAll } from '/@/utils/authFunction';

// 引入组件
const LimitsFrontEndPage = defineAsyncComponent(() => import('/@/views/limits/frontEnd/page/index.vue'));
const Auth = defineAsyncComponent(() => import('/@/components/auth/auth.vue'));
const Auths = defineAsyncComponent(() => import('/@/components/auth/auths.vue'));
const AuthAll = defineAsyncComponent(() => import('/@/components/auth/authAll.vue'));
import { scriptApi } from '/@/api/script/index';
import router from '/@/router';


const state = reactive<SysRoleState>({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			search: '',
			pageNum: 1,
			pageSize: 10,
		},
	},
});
// 单个权限验证
const onAuthClick = () => {
	if (!auth('btn.add')) ElMessage.error('抱歉，您没有权限！');
	else ElMessage.success('恭喜，您有权限！');
};
// 多个权限验证，满足一个则为 true
const onAuthsClick = () => {
	if (!auths(['btn.add', 'btn.edit', 'btn.del', 'btn.link'])) ElMessage.error('抱歉，您没有权限！');
	else ElMessage.success('恭喜，您有权限！');
};
// 多个权限验证，全部满足则为 true
const onAuthAllClick = () => {
	if (!authAll(['btn.add', 'btn.edit', 'btn.del', 'btn.link'])) ElMessage.error('抱歉，您没有权限！');
	else ElMessage.success('恭喜，您有权限！');
};


const onRadio = async () => {
	scriptApi().getHomeWork().then(res => {
		state.tableData.data = res.data;
		for (let i = 0; i < state.tableData.data.length; i++) {
			state.tableData.param.states.push(res.data[i].hid)
		}
	})


};

//格式化后端返回来的时间
function getLocalTime(value:any) {
    let time = value.endtime[0] + '-' + value.endtime[1] + '-' + value.endtime[2] + ' ' + value.endtime[3] + ':' + value.endtime[4] + ':' + value.endtime[5]
    return time
}

//跳转到具体页面
const Jump = (scope: any) => {
	localStorage.setItem('hid', JSON.stringify(scope.row.hid))
	router.push("/script")
}
// 页面加载时
onMounted(() => {
	onRadio()

});

</script>

<style scoped lang="scss">
.flex-warp {
	display: flex;
	flex-wrap: wrap;
	align-content: flex-start;
	margin: 0 -5px;
	.flex-warp-item {
		padding: 5px;
		.flex-warp-item-box {
			width: 100%;
			height: 100%;
		}
	}
}
</style>
